#!/bin/bash

#Desc:install php7 by source
#Author:zhang huan huan
#Create:2020-0907
#update:
#Usage: $1 source path

#install rely by pbp 
yum -y install libxml2-devel libjpeg-devel libpng-devel freetype-devel curl-devel openssl-devel

#unpack tar 

mkdir -p $PWD/php7
tar -xf $1 -C $PWD/php7
sourcePath=$PWD/php7/*/
cd $sourcePath

#configure 
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-libzip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts

#make and install
make && make install 

#php conf files 
cp $sourcePath/php.ini-development /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

#set service init files
cp $sourcePath/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on

#set profile
echo 'export PATH=$PATH:/usr/local/php/bin' >> /etc/profile
source /etc/profile


#start php
service php-fpm start
